﻿@model StockShark.Models.BrokerageAccount

@{
    ViewBag.Title = "Szczegóły rachunku - " + Model.Name;
    ViewBag.Header = "Szczegóły rachunku - " + Model.Name;
    ViewBag.TotalShares = 0.00M;
    ViewBag.TotalCurrencies = 0.00M;
    ViewBag.TotalMaterials = 0.00M;
}

@Html.Partial("_BAMenuPartial")

<h4>Saldo</h4>
<ul>
<li>Wolne środki: <strong>@Html.DisplayFor(model => Model.Balance) PLN</strong></li>
<li>Łączna wartość rachunku: <strong>@Html.DisplayFor(model => Model.TotalValue) PLN</strong></li>
</ul>

<h4>Nowe zlecenie</h4>
<ul>
<li>@Html.ActionLink("Złóż zlecenie kupna", "BuyList", "Order", new { account = Model.Name }, null)</li>
<li>@Html.ActionLink("Złóż zlecenie sprzedaży", "SellList", "Order", new { account = Model.Name }, null)</li>
</ul>

<h4>Zawartość portfela</h4>
@if (Model.OwnedInstruments.Count() > 0)
{
<table class="full">
@if (Model.OwnedInstruments.Where(r => r.Paper.GetType().Name.Equals("Share")).Count() > 0)
{        
    <tr>
        <th class="section" colspan="5">Akcje</th>
    </tr>
    <tr>
        <th>Nazwa</th>
        <th>Ilość</th>
        <th>Aktualna cena (PLN)</th>
        <th>Łączna wartość (PLN)</th>
        <th></th>
    </tr>
    foreach (var oi in Model.OwnedInstruments.Where(r => r.Paper.GetType().Name.Equals("Share")))
    {
    <tr>
        <td>@Html.ActionLink(oi.Paper.Name, "Details", "Quotations", new { item = oi.Paper.Id }, null)</td>
        <td>@Html.DisplayFor(item => oi.Quantity)</td>
        <td>@Html.DisplayFor(item => oi.Paper.EstimatedPrice)</td>
        <td>@Html.DisplayFor(item => oi.TotalValue)</td>
        <td>
        @Html.ActionLink("Kup więcej", "Buy", "Order", new { account = Model.Name, item = oi.PaperId }, null) |
        @Html.ActionLink("Sprzedaj", "Sell", "Order", new { account = Model.Name, item = oi.PaperId }, null)
        </td>
    </tr>
        ViewBag.TotalShares += oi.TotalValue;
    }
    <tr>
        <th></th>
        <th></th>
        <th>Suma:</th>
        <th>@ViewBag.TotalShares PLN</th>
        <th></th>
    </tr>
}
@if (Model.OwnedInstruments.Where(r => r.Paper.GetType().Name.Equals("Currency")).Count() > 0)
{        
    <tr>
        <th class="section" colspan="5">Waluty</th>
    </tr>
    <tr>
        <th>Nazwa</th>
        <th>Ilość</th>
        <th>Aktualna cena (PLN)</th>
        <th>Łączna wartość (PLN)</th>
        <th></th>
    </tr>
    foreach (var oi in Model.OwnedInstruments.Where(r => r.Paper.GetType().Name.Equals("Currency")))
    {
    <tr>
        <td>@Html.ActionLink(oi.Paper.Name, "Details", "Quotations", new { item = oi.Paper.Id }, null)</td>
        <td>@Html.DisplayFor(item => oi.Quantity)</td>
        <td>@Html.DisplayFor(item => oi.Paper.EstimatedPrice)</td>
        <td>@Html.DisplayFor(item => oi.TotalValue)</td>
        <td>
        @Html.ActionLink("Kup więcej", "Buy", "Order", new { account = Model.Name, item = oi.PaperId }, null) |
        @Html.ActionLink("Sprzedaj", "Sell", "Order", new { account = Model.Name, item = oi.PaperId }, null)
        </td>
    </tr>
        ViewBag.TotalCurrencies += oi.TotalValue;
    }
    <tr>
        <th></th>
        <th></th>
        <th>Suma:</th>
        <th>@ViewBag.TotalCurrencies PLN</th>
        <th></th>
    </tr>
}
@if (Model.OwnedInstruments.Where(r => r.Paper.GetType().Name.Equals("Material")).Count() > 0)
{        
    <tr>
        <th class="section" colspan="5">Surowce</th>
    </tr>
    <tr>
        <th>Nazwa</th>
        <th>Ilość</th>
        <th>Aktualna cena (PLN)</th>
        <th>Łączna wartość (PLN)</th>
        <th></th>
    </tr>
    foreach (var oi in Model.OwnedInstruments.Where(r => r.Paper.GetType().Name.Equals("Material")))
    {
    <tr>
        <td>@Html.ActionLink(oi.Paper.Name, "Details", "Quotations", new { item = oi.Paper.Id }, null)</td>
        <td>@Html.DisplayFor(item => oi.Quantity)</td>
        <td>@Html.DisplayFor(item => oi.Paper.EstimatedPrice)</td>
        <td>@Html.DisplayFor(item => oi.TotalValue)</td>
        <td>
        @Html.ActionLink("Kup więcej", "Buy", "Order", new { account = Model.Name, item = oi.PaperId }, null) |
        @Html.ActionLink("Sprzedaj", "Sell", "Order", new { account = Model.Name, item = oi.PaperId }, null)
        </td>
    </tr>
        ViewBag.TotalMaterials += oi.TotalValue;
    }
    <tr>
        <th></th>
        <th></th>
        <th>Suma:</th>
        <th>@ViewBag.TotalMaterials PLN</th>
        <th></th>
    </tr>
}
</table>
}
else
{
    <p>Twój portfel inwestycyjny jest pusty. Najwyższy czas w coś @Html.ActionLink("zainwestować", "BuyList", "Order", new { account = Model.Name }, null).</p>
}
